package com.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import com.root.Person;

public class CollectionIterator {

	public static void main(String[] args) {

		List<Person> personList = new ArrayList<Person>();

		Person person = new Person();
		person.setName("name4");
		person.setId("4");

		personList.add(person);

		person = new Person();
		person.setName("name3");
		person.setId("3");
		personList.add(person);

		person = new Person();
		person.setName("name1");
		person.setId("1");
		personList.add(person);

		person = new Person();
		person.setName("name2");
		person.setId("2");
		personList.add(person);

		 

		//System.out.println(personList.get(4 - 1).getName());
		//System.out.println(personList.get(0).getName());

		
	   Collections.sort(personList, new PersonComparator());
	   
	   
		
		for (Iterator<Person> iterator = personList.iterator(); iterator
				.hasNext();) {
			Person personObj = iterator.next();
			
			System.out.println(personObj.getName());

		}

	}

}
